<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1-transitional.dtd">
<html>
<head>
<title>jqMock FAQ</title>
<link type="text/css" rel="stylesheet"  href="jqMock.css" />
<link type="text/css" rel="stylesheet" href="highlighter/SyntaxHighlighter.css" />
</head>
<body>
<h1>jqMock FAQ</h1>

<ul id="nav">
	<li><a href="http://code.google.com/p/jqmock/">Home</a></li>
	<li><a href="download.html">Download</a></li>
	<li><a href="userguide.html">UserGuide</a></li>
	<li><a href="api.html">API</a></li>
	<li><a class="current">FAQ</a></li>
	<li><a href="../src/jqMock.html">Tests</a></li>
	<li class="last"><a href="http://users.tpg.com.au/fuzziman/jqmock/jscoverage/jscoverage.html?jqMock.html">Coverage</a></li>
</ul><br style="clear:both;"/>

<h3>What is different about jqMock?</h3>

<p>jqMock takes a pragmatic approach to mocking which is more suited to the way javascript is used today.
Most mock libraries are written with the aim of mocking out object dependencies, to allow easy TDD of objects.
However, javascript is still most widely used as scripting language, providing snippets of behaviour on
web pages, and doesn't have a large set of OO classes. This is especially true for a library 
like jQuery, which is aimed at lightweight progressive enhancement work.</p>

<p>That's why it makes more sense to mock specific functions on an object
rather than the entire object, because you usually only want to intercept certain functionality,
while retaining the normal behaviour in other parts of the object.</p>
<p>A good example is the native window dialog, e.g. <strong>window.alert</strong>. You cannot programmatically access the dialog in a unit test,
but you will want to setup an expectation that it was called with the correct message.
jqMock allows you to intercept the method call, and setup expectations on it:
</p>
<pre name="code" class="js:nocontrols:nogutter">
	var alertMock = new jqMock.Mock(window, "alert");
	alertMock.modify().args("hello world");
	// some code that calls alert("hello world");
	alertMock.verify();
</pre>

<h3>Does jqMock support mocking of object attributes?</h3>
<p>Not at the moment. Currently, only functions are supported.
Support will be added in the next release to mock out getters and setters.
This will be especially useful for mocking out the window.location setter.
</p>


<h3>But I want to mock objects!</h3>
<p>It will be easy to extend the functionality in jqMock to do standard mock object testing too. I will be focussing on this in the next release.</p>


<script type="text/javascript" src="highlighter/shCore.js"></script>
<script type="text/javascript" src="highlighter/shBrushJScript.js"></script>
<script type="text/javascript" src="highlighter/shBrushXml.js"></script>
<script type="text/javascript">
dp.SyntaxHighlighter.ClipboardSwf = 'highlighter/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
</script>
</body>
</html>
